package qit.itmiaojie.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import qit.itmiaojie.pojo.Role;
import qit.itmiaojie.service.RoleService;

import java.util.List;

@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;




    /**
     * 添加角色
     * @param role
     * @return
     */
    @RequestMapping("/add")
    public String add(Role role){
        roleService.addRole(role);
        System.out.println(role);
        return "redirect:/role/findAll";
    }


    /**
     * 查询所有角色 返回list集合
     * @param modelAndView
     * @return
     */
    @RequestMapping("/findAll")
    public ModelAndView findAll(ModelAndView modelAndView){
        List<Role> roleList = roleService.findAll();
        modelAndView.addObject("roleList",roleList);
        modelAndView.setViewName("role-list");
        return modelAndView;
    }
    @RequestMapping("/test")
    public ModelAndView test(ModelAndView modelAndView){
        modelAndView.setViewName("role-list");
        return modelAndView;
    }




}
